# 加载文件

import requests


def download(url):
    """
    从指定的 URL 中下载文件并存储到当前目录
    url: 要下载页面内容的网址
    """
    # 检测网页存在与否
    try:
        req = requests.get(url)
    except requests.exceptions.MissingSchema:
        print('Invalid URL {}'.format(url))
        return
    # 检测网页权限
    if req.status_code == 403:
        print('You do not have this authority to access this page.')
        return
    filename = url.split('/')[-1]   # 最后一个 / 后面的为文件名
    with open(filename, 'w', encoding='UTF-8') as fileObj:
        fileObj.write(req.content.decode('UTF-8'))
    print('Download Over.')


if __name__ == '__main__':
    fileUrl = input('Please Enter a URL:')
    download(fileUrl)
